package dao

import (
	"gitee.com/CrazyMage/blog-service/internal/model"
	"github.com/jinzhu/gorm"
)

func (d *Dao) CreateUser(user *model.User) error {

	return user.Create(d.engine)
}

func (d *Dao) GetUserByEmail(email string) (*model.User, error) {

	user := model.User{
		Email: email,
	}
	return user.GetByEmail(d.engine)
}

func (d *Dao) GetUserByAccount(account string) (*model.User, error) {

	user := model.User{
		Account: account,
	}
	return user.GetByAccount(d.engine)
}

func (d *Dao) DeleteUserById(id uint) (int64, error) {
	user := model.User{
		Model: gorm.Model{
			ID: id,
		},
	}
	return user.Delete(d.engine)
}

func (d *Dao) UpdateUserByFields(id uint, values map[string]any) (int64, error) {
	user := model.User{
		Model: gorm.Model{
			ID: id,
		},
	}

	return user.Update(d.engine, values)
}
